package com.identity.identity.dect.view;

import android.graphics.Bitmap;
import android.util.LruCache;

public final class SimpleImageStore {

    private static final SimpleImageStore INSTANCE = new SimpleImageStore();

    public static SimpleImageStore getInstance() {
        return INSTANCE;
    }

    private final LruCache<String, Bitmap> mBitmapCache;

    private SimpleImageStore() {
        int maxMemory = (int) (Runtime.getRuntime().totalMemory()/1024);
        int cacheSize = maxMemory/8;
        mBitmapCache = new LruCache<String,Bitmap>(cacheSize){
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes()*value.getHeight()/1024;
            }
        };
    }

    public void put(final String key, final Bitmap bitmap) {
        this.mBitmapCache.put(key, bitmap);
    }
    public Bitmap get(final String key) {
        return this.mBitmapCache.get(key);
    }
    public void removeElement(String key) {
        this.mBitmapCache.remove(key);
    }
}
